package com;

import com.baidu.aip.bodyanalysis.AipBodyAnalysis;
import com.baidu.aip.imageprocess.AipImageProcess;
import org.json.JSONObject;

import java.net.URLEncoder;
import java.util.HashMap;

/**
 * Created by lsy
 * on 2020/6/23 9:57.
 */
public class TestBlack {
    public static final String APP_ID = "20545677";
    public static final String API_KEY = "EnSFRIdQMqehyQal3mRvHUQV";
    public static final String SECRET_KEY = "2mdTjU9qHyzU3qi00HeR7Zaj2nPosIQZ";

  /*  public static void main(String[] args) {
        // 初始化一个AipImageProcess
        AipImageProcess client = new AipImageProcess(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 可选：设置代理服务器地址, http和socket二选一，或者均不设置
        client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
        client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理

        // 调用接口
        String path = "test.jpg";
        JSONObject res = client.imageProcess(path, new HashMap<String, String>());
        System.out.println(res.toString(2));

    }*/

    public static String colourize() {
        // 请求url
        String url = "https://aip.baidubce.com/rest/2.0/image-process/v1/colourize";
        try {
            // 本地文件路径
            String filePath = "D://01-2.jpg";
            byte[] imgData = FileUtil.readFileByBytes(filePath);
            String imgStr = Base64Util.encode(imgData);
            String imgParam = URLEncoder.encode(imgStr, "UTF-8");

            String param = "image=" + imgParam;

            // 注意这里仅为了简化编码每一次请求都去获取access_token，线上环境access_token有过期时间， 客户端可自行缓存，过期后重新获取。
            String accessToken = "24.8deb6f39736bbc7fc9f5777113c1d8b2.2592000.1595468639.282335-20545677";

            String result = HttpUtil.post(url, accessToken, param);
            System.out.println(result);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        TestBlack.colourize();
    }
}
